/**
 * Project Reactor
 */



#include "Socket.h"

#include <sys/socket.h>
#include <iostream>
#include <stdio.h>
#include <unistd.h>
using std::endl;
using std::cout;
/**
 * Socket implementation
 */


Socket::Socket() {
    //创建套接字
    _fd = ::socket(AF_INET, SOCK_STREAM, 0);
    cout << "create sockfd = " << _fd << endl;
    if(_fd == -1)
        perror("socket");

}

Socket::Socket(int fd)
:_fd(fd)
{

}

Socket::~Socket() {
    //关闭套接字
    close(_fd);

}

/**
 * @return int
 */
int Socket::fd() const{
    return _fd;
}

/**
 * @return void
 */
void Socket::shutDownWrite() {
    int ret = shutdown(_fd, SHUT_WR);
    if(ret == -1)
        perror("shutdown");
    return;
}
